package com.linglan.modules.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linglan.modules.user.dao.PatientDao;
import com.linglan.modules.user.dto.result.PatientResult;
import com.linglan.modules.user.entity.Patient;
import com.linglan.modules.user.service.PatientService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 患者表(Patient)表服务实现类
 *
 * @author makejava
 * @since 2025-05-03 19:59:45
 */
@Service("patientService")
public class PatientServiceImpl extends ServiceImpl<PatientDao, Patient> implements PatientService {

    /**
     * 根据id查询患者信息
     *
     * @param ids
     * @return
     */
    @Override
    public Map<Long, PatientResult> findGroupById(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return new HashMap<>();
        }
        LambdaQueryWrapper<Patient> queryWrapper = Wrappers.lambdaQuery();
        if (CollectionUtils.size(ids) ==1) {
            queryWrapper.eq(Patient::getId, ids.get(0));
        } else {
            queryWrapper.in(Patient::getId, ids);
        }
        List<Patient> list = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(list)) {
            HashMap<Long, PatientResult> patientResultMap = new HashMap<>();
            for (Patient patient : list) {
                PatientResult result = new PatientResult();
                result.setId(patient.getId());
                result.setName(patient.getName());
                patientResultMap.put(patient.getId(), result);
            }
            return patientResultMap;
        }
        return new HashMap<>();
    }
}

